#include "StateMangager.h"

StateMangager* StateMangager::m_pInstance = 0;

StateMangager::~StateMangager()
{
}

void StateMangager::render()
{
	if (m_pCurrentState)
		m_pCurrentState->render();
}

void StateMangager::update(bool isPaused, float dt)
{
	// Check switch state
	if (m_pCurrentState != m_pNextState)
	{
		// Exit current state
		if (m_pCurrentState)
		{
			m_pCurrentState->exit();
			delete m_pCurrentState;
		}
		if (m_pNextState)
		{
			m_pNextState->init();
		}
		m_pCurrentState = m_pNextState;
	}
	// Update current state
	if (m_pCurrentState)
	{
		if (!isPaused)
		{
			m_pCurrentState->update(dt);
		}
		m_pCurrentState->render();
	}
}

void StateMangager::switchState(GameState* next_state)
{
	m_pNextState = next_state;
}